Translate '\' to '/' for submodule names
authorAlex Crichton <alex@alexcrichton.com>
Mon, 16 Feb 2015 04:23:09 +0000 (20:23 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 2 Mar 2015 23:51:13 +0000 (15:51 -0800)
Apparently git submodules are checked in as '/' not '\' so if a '\' leaks
through it'll end up not being found!

Closes #1299

src/cargo/sources/path.rs
tests/test_cargo_compile_git_deps.rs

index 26a673d15795a1fb64e7a0c8f6a5c7c8f5ef36bf..11352770e541f6dffe920cfedeb452040e0b6d79 100644 (file)
@@ -162,7 +162,10 @@ impl<'a, 'b> PathSource<'a, 'b> {
                 let rel = try!(rel.to_str().chain_error(|| {
                     human(format!("invalid utf-8 filename: {}", rel.display()))
                 }));
-                let submodule = try!(repo.find_submodule(rel));
+                // Git submodules are currently only named through `/` path
+                // separators, explicitly not `\` which windows uses. Who knew?
+                let rel = rel.replace(r"\", "/");
+                let submodule = try!(repo.find_submodule(&rel));
                 let repo = match submodule.open() {
                     Ok(repo) => repo,
                     Err(..) => continue,
index c8bb12f6d97d5dbe25f55542cf376f6b0f67f377..df4aeff8131e52625796f55996fa41c2955d2e5a 100644 (file)
@@ -51,7 +51,8 @@ fn add(repo: &git2::Repository) {
 
 fn add_submodule<'a>(repo: &'a git2::Repository, url: &str,
                      path: &Path) -> git2::Submodule<'a> {
-    let mut s = repo.submodule(url, path, false).unwrap();
+    let path = path.to_str().unwrap().replace(r"\", "/");
+    let mut s = repo.submodule(url, Path::new(&path), false).unwrap();
     let subrepo = s.open().unwrap();
     let mut origin = subrepo.find_remote("origin").unwrap();
     origin.add_fetch("refs/heads/*:refs/heads/*").unwrap();
@@ -1658,12 +1659,13 @@ test!(dont_require_submodules_are_checked_out {
         "#)
         .file("build.rs", "fn main() {}")
         .file("src/lib.rs", "")
+        .file("a/foo", "")
     }).unwrap();
     let git2 = git_repo("dep2", |p| p).unwrap();
 
     let repo = git2::Repository::open(&git1.root()).unwrap();
     let url = path2url(git2.root()).to_string();
-    add_submodule(&repo, &url, &Path::new("submodule"));
+    add_submodule(&repo, &url, &Path::new("a/submodule"));
     commit(&repo);
 
     git2::Repository::init(&project.root()).unwrap();